package com.order.controller;

import com.alibaba.fastjson.JSONObject;
import com.bhudy.exception.SysException;
import com.order.entity.*;
import com.order.service.*;
import com.bhudy.enums.Relation;
import com.bhudy.exception.SysExceptionCode;
import com.sys.utils.RequestUtils;
import com.sys.utils.ShiroUtils;
import com.sys.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bhudy.base.QueryFilter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 工单管理
 *
 * @Author 卞洪业
 * @Description ResOrderController
 * @Date Wed Feb 19 17:04:47 CST 2020
 */
@RestController
public class ResOrderController {

    @Autowired
    private ResOrderService resOrderService;
    @Autowired
    private ResOrderTypeService resOrderTypeService;
    @Autowired
    private ResOrderStageService resOrderStageService;
    @Autowired
    private ResOrderStageTemplateService resOrderStageTemplateService;

    /**
     * 获取ResOrder表的数据
     *
     * @param page  页数{1}
     * @param limit 显示数量{10}
     * @param type  查询类型0全部，1处理，2完结
     * @return ResOrder的list
     */
    @GetMapping(value = "/api/v1/resOrders")
    public Object getAll(Integer page, Integer limit, Integer type, String resOrderName) {
        QueryFilter queryFilter = new QueryFilter();
        if (type == null || type == 0) {
            queryFilter.sql("where (user_id = ? or create_by = ? or update_by = ? or res_order_id in (select res_order_id from (select distinct res_order_id from res_order_stage where user_id = ?) as table_1))", ShiroUtils.getUserId(), ShiroUtils.getUserId(), ShiroUtils.getUserId(), ShiroUtils.getUserId());
        } else if (type == 1) {
            queryFilter.sql("where (user_id = ?) and (stage != 5 or (stage = 5 and order_status = 1))", ShiroUtils.getUserId());
        } else if (type == 2) {
            queryFilter.sql("where (user_id = ? or create_by = ? or update_by = ? or res_order_id in (select res_order_id from (select distinct res_order_id from res_order_stage where user_id = ?) as table_1))", ShiroUtils.getUserId(), ShiroUtils.getUserId(), ShiroUtils.getUserId(), ShiroUtils.getUserId());
            queryFilter.sql("and (stage = 5 and order_status = 2)");
        } else if (type == 3) {
            queryFilter.sql("where res_order_type_id in (select res_order_type_id from res_order_stage_template rost" +
                            " where resOrder.res_order_type_id = rost.res_order_type_id and resOrder.stage = rost.stage and resOrder.stage_sort = rost.stage_sort" +
                            " and kpi is not null and kpi != 0 and (kpi / 1000 - (unix_timestamp(NOW()) - unix_timestamp(resOrder.update_date)) < 0))" +
                            " and (user_id = ? or create_by = ? or update_by = ? or res_order_id in (select res_order_id from (select distinct res_order_id from res_order_stage where user_id = ?) as table_1))",
                    ShiroUtils.getUserId(), ShiroUtils.getUserId(), ShiroUtils.getUserId(), ShiroUtils.getUserId());
        }

        if (resOrderName != null && !resOrderName.equals("")) {
            queryFilter.andLike("resOrderName", "%" + resOrderName + "%");
        }

        queryFilter.and("status", Relation.NOT_EQUAL, 1).orderDESC("createDate");

        if (page != null && limit != null) queryFilter.limit(--page, limit);
        int count = resOrderService.count(queryFilter);
        List<Map<String, Object>> resOrderMapList = resOrderService.getResOrderMapList(resOrderService.findList(queryFilter));

        return RequestUtils.printMapJson(0, count, resOrderMapList);
    }

    @GetMapping(value = "/api/v1/resOrder")
    public Object get(Long resOrderId) {
        return RequestUtils.printMapJson(0, resOrderService.getResOrderById(resOrderId));
    }

    @PostMapping(value = "/api/v1/resOrder")
    public Object insert(@RequestBody String json) {
        ResOrder resOrder = JSONObject.parseObject(json, ResOrder.class);

        resOrder.setStage(ResOrder.Stage.CREATE.code);
        resOrder.setStageSort(1);
        resOrder.setOrderStatus(ResOrder.getOrderStatus(ResOrder.Stage.CREATE.code, 1));
        resOrder.setUserId(ShiroUtils.getUserId());
        ResOrderType resOrderType = resOrderTypeService.get(resOrder.getResOrderTypeId());
        if (resOrderType == null) throw new SysException(SysExceptionCode.CODE_40034);
        resOrder.setResObjType(resOrderType.getResObjType());

        resOrder.setSource(ResOrder.SOURCE_USER);

        resOrderService.insert(resOrder);
        return RequestUtils.printMapJson(0, resOrder.getResOrderId());
    }

    @PutMapping(value = "/api/v1/resOrder")
    public Object update(@RequestBody String json) {
        ResOrder resOrder = JSONObject.parseObject(json, ResOrder.class);
        ResOrder resOrder1 = resOrderService.get(resOrder.getResOrderId());
        if (resOrder1 == null || resOrder1.getStatus() == 1) throw new SysException(SysExceptionCode.CODE_40002);
        if (resOrder1.getStage() != ResOrder.Stage.CREATE.code) throw new SysException(SysExceptionCode.CODE_40033);
        if (resOrder.getUserId() != null && !resOrder.getUserId().equals("") &&
                (!resOrder.getUserId().equals(ShiroUtils.getUserId()) || !resOrder.getCreateBy().equals(ShiroUtils.getUserId())))
            throw new SysException(SysExceptionCode.CODE_40013);

        resOrder.setUserId(null);
        resOrder.setStage(null);
        resOrder.setStageSort(null);
        resOrder.setOrderStatus(null);

        resOrderService.update(resOrder);
        return RequestUtils.printMapJson(0, resOrder.getResOrderId());
    }

    @DeleteMapping(value = "/api/v1/resOrders")
    public Object delete(@RequestBody String json) {
        return RequestUtils.printMapJson(0, resOrderService.delete(JSONObject.parseObject(json, Long[].class)));
    }

    @GetMapping(value = "/api/v1/resOrder/statistics/assessByPersonal")
    public Object statisticsAssessByPersonal() {
        QueryFilter queryFilter = new QueryFilter();
        List<ResOrderStage> resOrderStageList = resOrderStageService.findList(queryFilter.and("createBy", ShiroUtils.getUserId()).or("handlingPersonal", ShiroUtils.getResPersonalId()));

        Set<Long> countIdSet = new HashSet<>();
        if (Utils.isBlank(resOrderStageList)) {
            for (ResOrderStage resOrderStage : resOrderStageList) {
                countIdSet.add(resOrderStage.getResOrderId());
            }
        }
        queryFilter.clear().and("handlingPersonal", ShiroUtils.getResPersonalId()).and("stage", Relation.IN, new Integer[]{2, 3, 4});
        Integer activityCount = resOrderService.count(queryFilter);

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("count", countIdSet.size());
        resultMap.put("activityCount", activityCount);

        return RequestUtils.printMapJson(resultMap);
    }

    /**
     * 绩效统计
     * 实时活动工单及平均统计
     *
     * @return
     */
    @GetMapping(value = "/api/v1/resOrder/statistics/assess")
    public Object statisticsAssess(String time) {
        QueryFilter queryFilter = new QueryFilter().and("status", Relation.NOT_EQUAL, 1);
        // queryFilter.sql("and (order_status != 1 and stage != 1)");
        if (time == null || time.equals("")) throw new SysException(SysExceptionCode.CODE_40003);
        queryFilter.and("createDate", Relation.BETWEEN, Utils.formatDateStr(time));
        List<ResOrder> resOrderList = resOrderService.findList(queryFilter);

        int count = 0; //总数量
        int activityCount = 0; //活跃数量
        int accomplishCount = 0; //完成数量
        int overtimeCount = 0; //超时数量
        int nowOvertimeCount = 0; //实时超时数量
        double accomplishRate = 0.0; //完成率
        double standardsRate = 0.0; //达标率
        int avgUseTime = 0; //平均使用时间（毫秒）

        Set<Long> overtimeIdSet = new HashSet<>();
        Set<Long> idSet = new HashSet<>();
        if (Utils.isBlank(resOrderList)) {
            queryFilter.clear().and("kpi", Relation.NOT_EQUAL, 0).and("kpi", Relation.IS_NOT_NULL);
            List<ResOrderStageTemplate> resOrderStageTemplateList = resOrderStageTemplateService.findList(queryFilter);
            Map<String, Integer> resOrderStageTemplateMap = new HashMap<>();
            if (Utils.isBlank(resOrderStageTemplateList)) {
                for (ResOrderStageTemplate resOrderStageTemplate : resOrderStageTemplateList) {
                    resOrderStageTemplateMap.put(resOrderStageTemplate.getResOrderTypeId() + "_" + resOrderStageTemplate.getStageSort(), resOrderStageTemplate.getKpi());
                }
            }


            for (ResOrder resOrder : resOrderList) {
                if (resOrder.getStage().equals(ResOrder.Stage.FINISH.code)) {
                    accomplishCount++;
                } else {
                    activityCount++;
                }
                count++;
                long useTime = new Date().getTime() - resOrder.getUpdateDate().getTime();
                String key = resOrder.getResOrderTypeId() + "_" + resOrder.getStageSort();
                if (resOrderStageTemplateMap.containsKey(key) && !resOrder.getStage().equals(ResOrder.Stage.FINISH.code)) {
                    if ((resOrderStageTemplateMap.get(key) - useTime) < 0) {
                        nowOvertimeCount++;
                        overtimeIdSet.add(resOrder.getResObjId());
                    }
                } else {
                    idSet.add(resOrder.getResOrderId());
                }
            }
        }


        if (idSet.size() != 0) {
            queryFilter.clear().and("resOrderId", Relation.IN, idSet.toArray()).sql("and (order_status != 1 and stage != 1)");
            List<ResOrderStage> resOrderStageList = resOrderStageService.findList(queryFilter);
            if (Utils.isBlank(resOrderStageList)) {
                for (ResOrderStage resOrderStage : resOrderStageList) {
                    if (resOrderStage.getQualified() != null && resOrderStage.getQualified() < 0) {
                        overtimeIdSet.add(resOrderStage.getResOrderId());
                    }
                    avgUseTime += resOrderStage.getUseTime();
                }
                avgUseTime = resOrderStageList.size() == 0 ? 0 : avgUseTime / resOrderStageList.size();
            }
        }

        overtimeCount = overtimeIdSet.size(); //超时数量
        accomplishRate = (Utils.formatDouble(accomplishCount) / Utils.formatDouble(count)) * 100; //完成数量/总数量=完成率
        standardsRate = ((Utils.formatDouble(count) - Utils.formatDouble(overtimeCount)) / count) * 100; //总数量-超时数量=达标数量，达标数量/总数量=达标率


        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("count", count);
        resultMap.put("activityCount", activityCount);
        resultMap.put("accomplishCount", accomplishCount);
        resultMap.put("overtimeCount", overtimeCount);
        resultMap.put("nowOvertimeCount", nowOvertimeCount);
        resultMap.put("accomplishRate", accomplishRate);
        resultMap.put("standardsRate", standardsRate);
        resultMap.put("avgUseTime", avgUseTime);

        return RequestUtils.printMapJson(resultMap);
    }

    /**
     * 绩效统计
     * 工单趋势，计算2个时间包含的工单当前状态数量
     *
     * @return
     */
    @GetMapping(value = "/api/v1/resOrder/statistics/timeTrend")
    public Object statisticsTimeTrend(String time) throws ParseException {
        if (time == null || time.equals("")) throw new SysException(SysExceptionCode.CODE_40003);

        String[] times = Utils.formatDateStr(time);
        QueryFilter queryFilter = new QueryFilter().and("status", Relation.NOT_EQUAL, 1).and("createDate", Relation.BETWEEN, times);
        List<ResOrder> resOrderList = resOrderService.findList(queryFilter);

        queryFilter.clear().and("stage", Relation.NOT_EQUAL, ResOrder.Stage.CREATE.code).and("stage", Relation.NOT_EQUAL, ResOrder.Stage.FINISH.code).and("createDate", Relation.LESS_THAN, times[0]);
        int count = resOrderService.count(queryFilter);

        Map<Long, Integer> createMap = new HashMap<>(); //创建工单
        Map<Long, Integer> activityMap = new HashMap<>(); //活动工单
        Map<Long, Integer> accomplishMap = new HashMap<>(); //完成工单
        Map<Long, Integer> overtimeMap = new HashMap<>(); //超时工单
        Long begTime = Utils.formatDate(times[0]).getTime();
        do {
            createMap.put(begTime, 0);
            activityMap.put(begTime, 0);
            accomplishMap.put(begTime, 0);
            overtimeMap.put(begTime, count);
        } while ((begTime += 86400000) < Utils.formatDate(times[1]).getTime());

        if (Utils.isBlank(resOrderList)) {
            queryFilter.clear().and("kpi", Relation.NOT_EQUAL, 0).and("kpi", Relation.IS_NOT_NULL);
            List<ResOrderStageTemplate> resOrderStageTemplateList = resOrderStageTemplateService.findList(queryFilter);
            Map<String, Integer> resOrderStageTemplateMap = new HashMap<>();
            if (Utils.isBlank(resOrderStageTemplateList)) {
                for (ResOrderStageTemplate resOrderStageTemplate : resOrderStageTemplateList) {
                    resOrderStageTemplateMap.put(resOrderStageTemplate.getResOrderTypeId() + "_" + resOrderStageTemplate.getStageSort(), resOrderStageTemplate.getKpi());
                }
            }

            Set<Long> idSet = new HashSet<>();
            for (ResOrder resOrder : resOrderList) {
                idSet.add(resOrder.getResOrderId());
            }
            queryFilter.clear().and("qualified", Relation.LESS_THAN, 0);
            if (idSet.size() != 0) {
                queryFilter.and("resOrderId", Relation.IN, idSet.toArray());
            }
            Set<Long> overtimeIdSet = new HashSet<>();
            List<ResOrderStage> resOrderStageList = resOrderStageService.findList(queryFilter);
            if (Utils.isBlank(resOrderList)) {
                for (ResOrderStage resOrderStage : resOrderStageList) {
                    overtimeIdSet.add(resOrderStage.getResOrderId());
                }
            }


            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            for (ResOrder resOrder : resOrderList) {
                Long createTime = simpleDateFormat.parse(simpleDateFormat.format(resOrder.getCreateDate())).getTime();
                if (createMap.containsKey(createTime)) {
                    createMap.put(createTime, createMap.get(createTime) + 1);
                }
                if (!resOrder.getStage().equals(ResOrder.Stage.CREATE.code) && !resOrder.getOrderStatus().equals(1) && !resOrder.getStage().equals(ResOrder.Stage.FINISH.code) && activityMap.containsKey(createTime)) {
                    if (activityMap.containsKey(createTime)) {
                        activityMap.put(createTime, activityMap.get(createTime) + 1);
                    }
                } else if (resOrder.getStage().equals(ResOrder.Stage.FINISH.code) && activityMap.containsKey(createTime)) {
                    if (accomplishMap.containsKey(createTime)) {
                        accomplishMap.put(createTime, accomplishMap.get(createTime) + 1);
                    }
                }
                if (overtimeIdSet.contains(resOrder.getResOrderId())) {
                    if (overtimeMap.containsKey(createTime) && !resOrder.getStage().equals(ResOrder.Stage.FINISH.code)) {
                        overtimeMap.put(createTime, overtimeMap.get(createTime) + 1);
                    }
                } else {
                    String key = resOrder.getResOrderTypeId() + "_" + resOrder.getStageSort();
                    long useTime = new Date().getTime() - resOrder.getUpdateDate().getTime();
                    if (resOrderStageTemplateMap.containsKey(key) && overtimeMap.containsKey(createTime) && (resOrderStageTemplateMap.get(key) - useTime) < 0) {
                        overtimeMap.put(createTime, overtimeMap.get(createTime) + 1);
                    }
                }
            }
        }

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("createList", Utils.mapToList(createMap));
        resultMap.put("activityList", Utils.mapToList(activityMap));
        resultMap.put("accomplishList", Utils.mapToList(accomplishMap));
        resultMap.put("overtimeList", Utils.mapToList(overtimeMap));

        return RequestUtils.printMapJson(resultMap);
    }

    /**
     * 根据类型分组统计
     *
     * @return
     */
    @GetMapping(value = "/api/v1/resOrder/statistics/resOrderType")
    public Object statisticsResOrderType(String time) throws ParseException {
        String sql = "select res_order_type_id resOrderTypeId, count(res_order_type_id) count from res_order where create_date between ? and ? group by res_order_type_id";

        QueryFilter queryFilter = new QueryFilter();
        if (time == null || time.equals("")) throw new SysException(SysExceptionCode.CODE_40003);
        String[] times = Utils.formatDateStr(time);
        queryFilter.putArgs(times[0]).putArgs(times[1]);

        List<Map<String, Object>> dataMapList = resOrderService.findMapList(sql, queryFilter);
        Map<Long, String> resOrderTypeIdAndNameMapping = resOrderTypeService.getMapping("resOrderTypeId", "typeName");
        List<Map<String, Object>> resultMapList = new ArrayList<>();
        int count = 0;
        if (Utils.isBlank(dataMapList)) {
            for (Map<String, Object> dataMap : dataMapList) {
                Map<String, Object> resultMap = new HashMap<>();
                String key = resOrderTypeIdAndNameMapping.get(Utils.formatLong(dataMap.get("resOrderTypeId")));
                if (key == null) {
                    key = "未知类型";
                }
                resultMap.put(key, dataMap.get("count"));
                resultMapList.add(resultMap);
                count += Utils.formatInt(dataMap.get("count"));
            }
        }

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("count", count);
        resultMap.put("resultList", resultMapList);

        return RequestUtils.printMapJson(0, resultMap);
    }


    /**
     * 绩效统计
     * 工单趋势，计算2个时间包含的工单当前状态数量
     *
     * @return
     */
    @GetMapping(value = "/api/v1/resOrder/statistics/sla")
    public Object statisticsSla(String time) {
        if (time == null || time.equals("")) throw new SysException(SysExceptionCode.CODE_40003);
        String[] times = Utils.formatDateStr(time);
        QueryFilter queryFilter = new QueryFilter();

        queryFilter.clear().and("status", Relation.NOT_EQUAL, 1);

        List<Map<String, Object>> slaDataMapList = new ArrayList<>();
        Integer handlingCount = 0;
        Integer handlingOvertimeCount = 0;
        Integer restsCount = 0;
        Integer restsOvertimeCount = 0;

        /*if (Utils.isBlank(resPersonalList)) {
            String sql = "where res_order_id in (select res_order_id from (select res_order_id from res_order where `status` != 1 and `stage` = 5 and create_date between ? and ?) as table_1)" +
                    " and ((`stage` != 5 and stage != 1) or (stage = 1 and order_status = 1))";
            queryFilter.clear().sql(sql, times[0], times[1]);
            List<ResOrderStage> resOrderStageList = resOrderStageService.findList(queryFilter);

            Map<String, List<ResOrderStage>> personalIdAndResOrderStageListMap = new HashMap<>(); // 其他阶段
            Map<String, List<ResOrderStage>> handlingPersonalIdAndResOrderStageListMap = new HashMap<>(); // 处理阶段
            Map<String, List<ResOrderStage>> createPersonalIdAndResOrderStageListMap = new HashMap<>(); // 创建
            if (Utils.isBlank(resOrderStageList)) {
                for (ResOrderStage resOrderStage : resOrderStageList) {
                    String key = resOrderStage.getHandlingPersonal();
                    List<ResOrderStage> orderStageList = new ArrayList<>();
                    orderStageList.add(resOrderStage);
                    if (resOrderStage.getStage().equals(ResOrder.Stage.CREATE.code)) {
                        if (createPersonalIdAndResOrderStageListMap.containsKey(key)) {
                            orderStageList.addAll(createPersonalIdAndResOrderStageListMap.get(key));
                        }
                        createPersonalIdAndResOrderStageListMap.put(key, orderStageList);
                    } else if (resOrderStage.getStage().equals(ResOrder.Stage.HANDLE.code) && resOrderStage.getOrderStatus().equals(2)) {
                        if (resOrderStage.getQualified() == null || resOrderStage.getQualified().equals(0)) continue;
                        if (handlingPersonalIdAndResOrderStageListMap.containsKey(key)) {
                            orderStageList.addAll(handlingPersonalIdAndResOrderStageListMap.get(key));
                        }
                        handlingPersonalIdAndResOrderStageListMap.put(key, orderStageList);
                    }

                    List<ResOrderStage> stageList = new ArrayList<>();
                    stageList.add(resOrderStage);
                    if (!resOrderStage.getStage().equals(ResOrder.Stage.CREATE.code)) {
                        if (resOrderStage.getQualified() == null || resOrderStage.getQualified().equals(0)) continue;
                        if (personalIdAndResOrderStageListMap.containsKey(key)) {
                            stageList.addAll(personalIdAndResOrderStageListMap.get(key));
                        }
                        personalIdAndResOrderStageListMap.put(key, stageList);
                    }
                }
            }

            for (ResPersonal resPersonal : resPersonalList) {
                String key = resPersonal.getId();
                Map<String, Object> slaDataMap = new HashMap<>();
                slaDataMap.put("resPersonalName", resPersonal.getName());
                slaDataMap.put("createCount", createPersonalIdAndResOrderStageListMap.containsKey(key) ? createPersonalIdAndResOrderStageListMap.get(key).size() : 0); // 创建工单
                slaDataMap.put("handlingCount", 0); // 处理总数
                slaDataMap.put("handlingOvertimeCount", 0); // 处理超时数量
                slaDataMap.put("restsCount", 0); // 其他阶段总数
                slaDataMap.put("restsOvertimeCount", 0); // 其他超时数量
                if (handlingPersonalIdAndResOrderStageListMap.containsKey(key)) {
                    List<ResOrderStage> orderStageList = handlingPersonalIdAndResOrderStageListMap.get(key);
                    if (Utils.isBlank(orderStageList)) {
                        handlingCount += orderStageList.size();
                        slaDataMap.put("handlingCount", orderStageList.size());
                        for (ResOrderStage resOrderStage : orderStageList) {
                            if (resOrderStage.getQualified() < 0) {
                                handlingOvertimeCount += 1;
                                slaDataMap.put("handlingOvertimeCount", Utils.formatInt(slaDataMap.get("handlingOvertimeCount")) + 1);
                            }
                        }
                    }
                }
                if (personalIdAndResOrderStageListMap.containsKey(key)) {
                    List<ResOrderStage> orderStageList = personalIdAndResOrderStageListMap.get(key);
                    if (Utils.isBlank(orderStageList)) {
                        restsCount += orderStageList.size();
                        slaDataMap.put("restsCount", orderStageList.size());
                        for (ResOrderStage resOrderStage : orderStageList) {
                            if (resOrderStage.getQualified() < 0) {
                                restsOvertimeCount += 1;
                                slaDataMap.put("restsOvertimeCount", Utils.formatInt(slaDataMap.get("restsOvertimeCount")) + 1);
                            }
                        }
                    }
                }

                slaDataMapList.add(slaDataMap);
            }
        }*/

        for (Map<String, Object> slaDataMap : slaDataMapList) {
            if (Utils.formatInt(slaDataMap.get("restsCount")).equals(0)) {
                slaDataMap.put("restsRate", 100.0);
            } else {
                slaDataMap.put("restsRate", (Utils.formatDouble(slaDataMap.get("restsCount")) - Utils.formatDouble(slaDataMap.get("restsOvertimeCount"))) / Utils.formatDouble(slaDataMap.get("restsCount")) * 100.0);
            }
        }

        Collections.sort(slaDataMapList, (o1, o2) -> {
            Double value1 = Utils.formatDouble(o1.get("restsCount"));
            Double value2 = Utils.formatDouble(o2.get("restsCount"));
            return value2.compareTo(value1);
        });

        Collections.sort(slaDataMapList, (o1, o2) -> {
            Double value1 = Utils.formatDouble(o1.get("restsRate"));
            Double value2 = Utils.formatDouble(o2.get("restsRate"));
            return value1.compareTo(value2);
        });

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("slaDataMapList", slaDataMapList);
        resultMap.put("handlingCount", handlingCount); // 处理数量
        resultMap.put("handlingOvertimeCount", handlingOvertimeCount); // 处理超时数量
        resultMap.put("handlingRate", (Utils.formatDouble(handlingCount) - Utils.formatDouble(handlingOvertimeCount)) / Utils.formatDouble(handlingCount) * 100.0); // 处理达标率
        resultMap.put("restsCount", restsCount); // 其他数量
        resultMap.put("restsOvertimeCount", restsOvertimeCount); // 其他超时数量
        resultMap.put("restsRate", (Utils.formatDouble(restsCount) - Utils.formatDouble(restsOvertimeCount)) / Utils.formatDouble(restsCount) * 100.0); // 其他达标率

        return RequestUtils.printMapJson(resultMap);
    }

}
